/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Main.java
 *
 * Created on Dec 13, 2011, 2:53:59 PM
 */
package reportchart.main;

import reportchart.object.ReadData;

/**
 *
 * @author PCLT
 */
public class Main extends javax.swing.JFrame {

    private static int flag = 0;
    private static int numberofFile = 0;
    private static Main instance = new Main();
    public boolean b = false;

    /** Creates new form Main */
    public Main() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        btn_Report = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        r_Oneday = new javax.swing.JRadioButton();
        r_Chooseday = new javax.swing.JRadioButton();
        r_All = new javax.swing.JRadioButton();
        r_Server1 = new javax.swing.JRadioButton();
        r_Server2 = new javax.swing.JRadioButton();
        r_Allserver = new javax.swing.JRadioButton();
        r_Version = new javax.swing.JRadioButton();
        r_Session = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jFile = new javax.swing.JMenu();
        jExit = new javax.swing.JMenuItem();

        jLabel2.setText("jLabel2");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        btn_Report.setFont(new java.awt.Font("Times New Roman", 0, 18));
        btn_Report.setText("Report");
        btn_Report.setEnabled(false);
        btn_Report.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ReportActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 48));
        jLabel3.setText("Report Chart");

        r_Oneday.setText("One day");
        r_Oneday.setEnabled(false);
        r_Oneday.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r_OnedayActionPerformed(evt);
            }
        });

        r_Chooseday.setText("Week");
        r_Chooseday.setEnabled(false);
        r_Chooseday.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r_ChoosedayActionPerformed(evt);
            }
        });

        r_All.setText("All");
        r_All.setEnabled(false);
        r_All.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r_AllActionPerformed(evt);
            }
        });

        r_Server1.setText("Server 1");
        r_Server1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r_Server1ActionPerformed(evt);
            }
        });

        r_Server2.setText("Server 2");
        r_Server2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r_Server2ActionPerformed(evt);
            }
        });

        r_Allserver.setText("All Server");
        r_Allserver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r_AllserverActionPerformed(evt);
            }
        });

        r_Version.setText("Version");
        r_Version.setEnabled(false);
        r_Version.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r_VersionActionPerformed(evt);
            }
        });

        r_Session.setText("Session");
        r_Session.setEnabled(false);
        r_Session.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                r_SessionActionPerformed(evt);
            }
        });

        jLabel1.setText("Choose server");

        jLabel4.setText("Choose file type");

        jLabel5.setText("Choose chart type");

        jFile.setText("File");

        jExit.setText("Exit");
        jExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jExitActionPerformed(evt);
            }
        });
        jFile.add(jExit);

        jMenuBar1.add(jFile);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(214, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btn_Report, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(353, 353, 353))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(260, 260, 260))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(r_Server1)
                                    .addComponent(jLabel1)
                                    .addComponent(r_Server2))
                                .addGap(112, 112, 112)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(r_Version)
                                    .addComponent(r_Session)))
                            .addComponent(r_Allserver))
                        .addGap(137, 137, 137)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(r_Chooseday)
                            .addComponent(r_All)
                            .addComponent(jLabel5)
                            .addComponent(r_Oneday, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(108, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(105, 105, 105)
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(r_Version)
                    .addComponent(r_Server1)
                    .addComponent(r_Oneday))
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(r_Session)
                    .addComponent(r_Server2)
                    .addComponent(r_Chooseday))
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(r_Allserver)
                    .addComponent(r_All))
                .addGap(52, 52, 52)
                .addComponent(btn_Report, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(133, 133, 133))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jExitActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jExitActionPerformed

    private void btn_ReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ReportActionPerformed
        this.dispose();
        ReadData rd = new ReadData();
        if (r_Server1.isSelected()) {
            if (r_Version.isSelected()) {
                if (r_Oneday.isSelected()) {
                    rd.readAuto("server1", 0);
                } else if (r_Chooseday.isSelected()) {
                    rd.readweek("server1", 0);
                } else if (r_All.isSelected()) {
                    rd.readall("server1", 0);
                }
            } else if (r_Session.isSelected()) {
                if (r_Oneday.isSelected()) {
                    rd.readAuto("server1", 1);
                } else if (r_Chooseday.isSelected()) {
                    rd.readweek("server1", 1);
                } else if (r_All.isSelected()) {
                    rd.readall("server1", 1);
                }
            }
        } else if (r_Allserver.isSelected()) {
            rd.readallServer(0);
        }
    }//GEN-LAST:event_btn_ReportActionPerformed

    private void r_OnedayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r_OnedayActionPerformed
        this.flag = 0;
        r_Chooseday.setSelected(false);
        r_All.setSelected(false);
        btn_Report.setEnabled(true);
    }//GEN-LAST:event_r_OnedayActionPerformed

    private void r_ChoosedayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r_ChoosedayActionPerformed
        r_Oneday.setSelected(false);
        r_All.setSelected(false);
        btn_Report.setEnabled(true);
//        this.b = true;
    }//GEN-LAST:event_r_ChoosedayActionPerformed

    private void r_AllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r_AllActionPerformed
        // TODO add your handling code here:
        btn_Report.setEnabled(true);
        r_Oneday.setSelected(false);
        r_Chooseday.setSelected(false);
    }//GEN-LAST:event_r_AllActionPerformed

    private void r_Server1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r_Server1ActionPerformed
        r_Server2.setSelected(false);
        r_Allserver.setSelected(false);
        r_Version.setEnabled(true);
        r_Session.setEnabled(true);
        if (r_Version.isSelected() || r_Session.isSelected()) {
            r_Oneday.setEnabled(true);
            r_Chooseday.setEnabled(true);
            r_All.setEnabled(true);
        }
    }//GEN-LAST:event_r_Server1ActionPerformed

    private void r_Server2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r_Server2ActionPerformed
        r_Server1.setSelected(false);
        r_Allserver.setSelected(false);
        r_Version.setEnabled(true);
        r_Session.setEnabled(true);
        if (r_Version.isSelected() || r_Session.isSelected()) {
            r_Oneday.setEnabled(true);
            r_Chooseday.setEnabled(true);
            r_All.setEnabled(true);
        }
    }//GEN-LAST:event_r_Server2ActionPerformed

    private void r_AllserverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r_AllserverActionPerformed
        r_Server1.setSelected(false);
        r_Server2.setSelected(false);
        btn_Report.setEnabled(true);
        r_Version.setEnabled(false);
        r_Session.setEnabled(false);
        r_Oneday.setEnabled(false);
        r_Chooseday.setEnabled(false);
        r_All.setEnabled(false);
    }//GEN-LAST:event_r_AllserverActionPerformed

    private void r_VersionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r_VersionActionPerformed
        r_Oneday.setEnabled(true);
        r_Chooseday.setEnabled(true);
        r_All.setEnabled(true);
        r_Session.setSelected(false);
    }//GEN-LAST:event_r_VersionActionPerformed

    private void r_SessionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_r_SessionActionPerformed
        r_Oneday.setEnabled(true);
        r_Chooseday.setEnabled(true);
        r_All.setEnabled(true);
        r_Version.setSelected(false);
    }//GEN-LAST:event_r_SessionActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Main().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_Report;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JMenuItem jExit;
    private javax.swing.JMenu jFile;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JMenuBar jMenuBar1;
    public static javax.swing.JRadioButton r_All;
    public static javax.swing.JRadioButton r_Allserver;
    public static javax.swing.JRadioButton r_Chooseday;
    public static javax.swing.JRadioButton r_Oneday;
    public static javax.swing.JRadioButton r_Server1;
    public static javax.swing.JRadioButton r_Server2;
    public static javax.swing.JRadioButton r_Session;
    public static javax.swing.JRadioButton r_Version;
    // End of variables declaration//GEN-END:variables
// class create open file action

    /**
     * @return the flag
     */
    public static int getFlag() {
        return flag;
    }

    /**
     * @param flag the flag to set
     */
    public static void setFlag(int flag) {
        Main.flag = flag;
    }

    /**
     * @return the numberofFile
     */
    public static int getNumberofFile() {
        return numberofFile;
    }

    /**
     * @param numberofFile the numberofFile to set
     */
    public static void setNumberofFile(int numberofFile) {
        Main.numberofFile = numberofFile;
    }

    /**
     * @return the instance
     */
    public static Main getInstance() {
        if (instance == null) {
            instance = new Main();
        }
        return instance;
    }
}
